﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using FTBS.Models.BLO;

namespace FTBS.Controllers
{
    public class AccessPermissionController : Controller
    {
        private UserBLO _userBlo = new UserBLO();

        /// <summary>
        /// check login of account and get role
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>roleName</returns>
        /// <author>HungPH</author>
        /// <date>3/4/2014</date>
        public String CheckLogin(String username, String password)
        {
            String roleName = "";
            roleName = _userBlo.GetRoleNameFromLogin(username, password);
            if (roleName != "")
            {
                this.Session["RoleName"] = roleName;
                this.Session["Account"] = _userBlo.LoadUserByUserName(username).FullName;
            }
            return roleName;
        }

        /// <summary>
        /// Log out
        /// </summary>
        /// <returns>true/false</returns>
        /// <author>hungph</author>
        /// <date>3/6/2014</date>
        public String LogOut()
        {
            this.Session["RoleName"] = null;
            this.Session["Account"] = null;
            return "Success";
        }

    }
}
